package com.mm.cloth;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.bumptech.glide.Glide;
import com.mm.cloth.model.Clothes;

import java.util.List;

/**
 * 旧版适配器，已被 com.mm.cloth.adapter.ClothesAdapter 替代
 * 保留此类是为了兼容性，新代码应使用 com.mm.cloth.adapter.ClothesAdapter
 */
public class ClothesAdapter extends RecyclerView.Adapter<ClothesAdapter.ViewHolder> {
    private List<Clothes> clothesList;
    private OnItemClickListener onItemClickListener;

    public ClothesAdapter(List<Clothes> clothesList) {
        this.clothesList = clothesList;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_clothes, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        Clothes clothes = clothesList.get(position);
        holder.tvName.setText(clothes.getName());
        holder.tvCategory.setText(clothes.getCategory());
        Glide.with(holder.itemView.getContext())
                .load(clothes.getImageUrl())
                .placeholder(R.drawable.bg_edittext_round_pink)
                .into(holder.ivImage);
        holder.itemView.setOnClickListener(v -> {
            if (onItemClickListener != null) {
                onItemClickListener.onItemClick(clothes);
            }
        });
    }

    @Override
    public int getItemCount() {
        return clothesList.size();
    }

    public void setOnItemClickListener(OnItemClickListener listener) {
        this.onItemClickListener = listener;
    }

    public interface OnItemClickListener {
        void onItemClick(Clothes clothes);
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        ImageView ivImage;
        TextView tvName, tvCategory;
        ViewHolder(View itemView) {
            super(itemView);
            ivImage = itemView.findViewById(R.id.ivClothes);
            tvName = itemView.findViewById(R.id.tvName);
            tvCategory = itemView.findViewById(R.id.tvCategory);
        }
    }
} 